const Controller = require('egg').Controller

class AnalyzeController extends Controller {
  async getColumnToCourseData() {
    const { ctx } = this
    const res = await ctx.service.statistics.analyze.getColumnToCourseData()
    if (res) {
      return ctx.renderBack(res)
    }
  }

  async getCategoryToCourseData() {
    const { ctx } = this
    const { channelId } = ctx.request.query
    const res = await ctx.service.statistics.analyze.getCategoryToCourseData(channelId)
    if (res) {
      return ctx.renderBack(res)
    }
  }

  // 获取课程评不同阶段评论数
  async getCourseComment() {
    const { ctx } = this
    const { courseId } = ctx.query
    const res = await ctx.service.statistics.analyze.getCourseComment(courseId)
    if (res) {
      return ctx.renderBack(res)
    }
  }

  // 统计课程类别下不同年份参课人数
  async getCategoryToPersonData() {
    const { ctx } = this
    const { categoryId } = ctx.query
    const res = await ctx.service.statistics.analyze.getCategoryPerson(categoryId)
    if (res) {
      return ctx.renderBack(res)
    }
    return res
  }

  // 统计每期课程参课人数
  async getTerminfoToPersonData() {
    const { ctx } = this
    const { categoryId } = ctx.query
    const res = await ctx.service.statistics.analyze.getTerminfoPerson(categoryId)
    if (res) {
      return ctx.renderBack(res)
    }
  }

  // 统计每周爬取数量
  async getWeekLog() {
    const { ctx } = this
    const res = await ctx.service.statistics.analyze.getWeekLog()
    if (res) {
      return ctx.renderBack(res)
    }
  }

  // 获取不同分期的数据规划
  async getplanStage() {
    const { ctx } = this
    const res = await ctx.service.statistics.analyze.planStage(ctx.query.categoryIds)
    if (res) {
      return ctx.renderBack(res)
    }
  }
}

module.exports = AnalyzeController
